package com.ruoyi.common.kafka;

import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.redis.RedisCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

@Component
public class KafkaConsumer {
    @Autowired
    RedisCache redisCache;

    @KafkaListener(topics = {"my_topic"}, groupId = "mysql-redis")
    @Transactional
    public void listen(String message) {
        String key = Constants.HOME_PAGE_DATA;
        if (message.equals("兼职数据发生更新")) {
            if (redisCache.hasKey(key)) {
                redisCache.deleteObject(key);
            }
        }
    }
}
